package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC724 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int pivotIndex(int[] nums) {
            int len = nums.length;
            int[] preSum = new int[nums.length + 1];
            for (int i = 0; i < nums.length; i++) {
                preSum[i + 1] = preSum[i] + nums[i];
            }

            for (int i = 0; i < nums.length; i++) {
                if (preSum[i] == preSum[len] - preSum[i + 1]) return i;
            }

            return -1;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[2, 1, -1]");
        System.out.println(solution.pivotIndex(arr));
    }

    public static void main(String[] args) throws Exception {
        LC724 an = new LC724();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
